home *** CD-ROM | disk | FTP | other *** search
/ MacHack 2000 / MacHack 2000.toast / pc / The Hacks / Genie / Projects / Pedestal / Source / Includes / XList.hh < prev    next >
Encoding:
Text File  |  2000-06-24  |  2.0 KB  |  76 lines

  1. /*
  2.     XList.hh
  3.     
  4.     Copyright 1996-1997 Joshua Juran
  5. */
  6.  
  7. /*
  8.     This program is free software; you can redistribute it and/or modify
  9.     it under the terms of the GNU General Public License as published by
  10.     the Free Software Foundation; either version 2 of the License, or
  11.     (at your option) any later version.
  12.  
  13.     This program is distributed in the hope that it will be useful,
  14.     but WITHOUT ANY WARRANTY; without even the implied warranty of
  15.     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  16.     GNU General Public License for more details.
  17.  
  18.     You should have received a copy of the GNU General Public License
  19.     along with this program; if not, write to the Free Software
  20.     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  21. */
  22.  
  23. #pragma once
  24.  
  25. #include <Types.h>
  26.  
  27. #include "XObject.hh"
  28.  
  29. class CXNode {
  30.     friend class XList;
  31. public:
  32.     CXNode(XObject *inNewDatum) : mNext(NULL), mDatum(inNewDatum->retain()) {}
  33.     ~CXNode() {mDatum->release();}
  34.     void AddNext(XObject *inNewDatum);
  35.     CXNode *RemoveNext();
  36.     CXNode *Next() const {return mNext;}
  37.     XObject *Datum() const {return mDatum;}
  38. protected:
  39.     CXNode *mNext;
  40.     XObject * mDatum;
  41. };
  42.  
  43.  
  44. class XList {
  45. // For debugging
  46. private:
  47.     unsigned long mNote;
  48. public:
  49.     XList() : mNote('list'), mHead(NULL) {}
  50.     ~XList();
  51.  
  52. protected:
  53.     CXNode *HeadNode() const {return mHead;}
  54.     // No, that's not a typo. No need to zero both of them.
  55.     CXNode *TailNode() const {return mHead ? mTail : NULL;}
  56.     CXNode *FindNode(XObject * inDatum) const;
  57.  
  58. public:
  59.     XObject *FirstDatum() const {return HeadNode() ? HeadNode()->Datum() : NULL;}
  60.     XObject *LastDatum() const {return TailNode() ? TailNode()->Datum() : NULL;}
  61.     XObject *Successor(XObject * inDatum) const {
  62.         return (FindNode(inDatum) && FindNode(inDatum)->Next())
  63.             ? FindNode(inDatum)->Next()->Datum()
  64.             : (XObject *)NULL;
  65.     }
  66.     
  67.     void Prepend(XObject *inNewDatum);
  68.     void Append(XObject *inNewDatum);
  69.     XObject *Behead();
  70.     void Remove(XObject *inVictim);
  71.     void Purge();
  72. protected:
  73.     CXNode *mHead;
  74.     CXNode *mTail;
  75. };
  76.